def natural(n): 
    if n < 2:
        return False
    for i in range(2, int(n**0,5) + 1):
        if n % i == 0:
            return False
    return True

def numbername(word):
    numbermap = {
        'zero': '0', 'one': '1',
        'two': '2', 'three': '3',
        'four': '4', 'five': '5',
        'six': '6', 'seven': '7',
        'eight': '8', 'nine': '9'}
    return numbermap.get(word, '')

def nearest_prime(n):
    if n < 2:
        return 2
    l = n - 1
    while not natural(l):
        l -= 1
    w = n + 1
    while not natural(w):
        w += 1
    if n - l <= w - n:
        return l
    else:
        return w

def main():
    words = input().split()
    if len(words) != 3:
        print("Wrong input")
        return
    num_str = ''.join([numbername(word) for word in words])
    if not num_str.isdigit() or not 100 <= int(num_str) <= 999:
        print("Wrong input")
        return
    num = int(num_str)
    print(nearest_prime(num))

if __name__:
    main()